package com.motu.monstercity.server.game.logic;

import com.motu.monstercity.protocol.CsGameSystem;
import com.motu.monstercity.protocol.CsGameSystem.CSGameSystemRedPointResponse;
import com.motu.monstercity.server.game.commondata.bag.ItemId;
import com.motu.monstercity.server.game.commondata.shop.Shop;
import com.motu.monstercity.server.game.commondata.shop.ShopConstant;
import com.motu.monstercity.server.game.userdata.TigerDrawRecord;
import com.motu.monstercity.server.game.userdata.UserInfo;
import com.motu.monstercity.server.game.userdata.UserShopLimit;

public class DrawManager extends DrawUserData {
    // 老虎机商店是否有干员,伙伴可以兑换
    public static boolean checkRedPointTigerDraw(CSGameSystemRedPointResponse.Builder builder, UserInfo userInfo){
        CsGameSystem.RedPoint_TigerDraw.Builder redPoint = CsGameSystem.RedPoint_TigerDraw.newBuilder();
        int shopType = ShopConstant.SHOP_TYPE_1;
        UserShopLimit userShopLimit = ShopManager.getUserShopLimit(userInfo.getId(), shopType);
        for (Shop shop : ShopManager.getShopMap().values()) {
            if (shop.getShopType() == shopType && ShopManager.checkShopLimit(userShopLimit, shop, 1) && BagManager.checkNeedItemNum(userInfo, shop.getPriceItemList())) // 老虎机商店,且限购次数未达到最大
            {
                redPoint.setShopBuy(true);
                builder.setTigerDraw(redPoint);
                return true;
            }
        }
        return false;
    }

    // 生成老虎机的抽奖获得记录，只有获得招募券时才记录
    public static void createTigerDrawRecord(UserInfo userInfo, int itemId, long itemNum) {
        if (itemId == ItemId.RECRUIT_ITEM && itemNum > 0) {
            TigerDrawRecord tigerDrawRecord = new TigerDrawRecord(userInfo.getServerId(), userInfo.getId(), userInfo.getUserName(), itemId, itemNum);
            tigerDrawRecord.doCreate();
        }
    }

}
